{extend name="common/main" /}
{block name="body"}
<!-- 标题 -->
    <div class="main-title">
        <h2>
           {:lang("_INVITATION_CODE_LIST_PAGE_")}
        </h2>
    </div>

    <!-- 按钮工具栏 -->
    <div class="">
        <div class="button-box">
            <button class="btn ajax-post btn" url="{:Url('admin/invite/delete',array('status'=>-1))}" target-form="ids">
               {:lang("_DELETE_")}
            </button>
            &nbsp;
            <button data-title={:lang("_GENERATE_THE_INVITATION_CODE_WITH_DOUBLE_")} modal-url="{:Url('admin/invite/createcode')}" data-role="modal_popup" class="btn">
               {:lang("_GENERATE_INVITATION_CODE_")}
            </button>
            &nbsp;
            <button class="btn ajax-post btn" url="{:Url('admin/invite/deletetrue',array('status'=>-1))}" target-form="ids">
               {:lang("_EMPTY_THE_USELESS_INVITATION_CODE_")}
            </button>
            &nbsp;
            <button class="btn" data-role="copy_code_list">
               {:lang("_BATCH_COPY_INVITATION_CODE_")}
            </button>
            &nbsp;
            <button class="btn"  data-role="copy_code_url_list">
               {:lang("_BATCH_COPY_INVITATION_LINK_")}
            </button>
            &nbsp;
            <button class="btn" data-role="cvs" data-url="{:Url('admin/invite/cvs')}">
               {:lang("_EXPORT_CVS_")}
            </button>
            &nbsp;
            <!-- 选择框select -->
            <div style="margin:10px auto">
                <style>
                    .oneselect {
                        display: inline-block;
                        margin-left: 10px;
                    }

                    .oneselect .title {
                        float: left;
                        line-height: 32px;
                    }

                    .oneselect .select_box {
                        float: left;
                        line-height: 32px;
                    }

                    .oneselect .select_box select {
                        min-width: 200px;
                    }
                </style>
                <form id="selectForm" method="get" action="{:Url('Admin/Invite/invite')}" class="form-dont-clear-url-param">
                    <div class="oneselect">
                        <div class="title">{:lang("_INVITATION_CODE_TYPE_")}{:lang("_COLON_")}</div>
                        <div class="select_box">
                            <select name="type" data-role="select_text" class="form-control">
                                {volist name="type_list" id="type"}
                                    {php}if($type['id']==$now_type){{/php}
                                    <option value="{$type.id}" selected>{$type.value}</option>
                                    {php}}else{{/php}
                                    <option value="{$type.id}">{$type.value}</option>
                                    {php}}{/php}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="oneselect">
                        <div class="select_box">
                            <select name="status" data-role="select_text" class="form-control">
                                <option value="1" selected>{:lang("_CAN_BE_REGISTERED_")}</option>
                                <option value="3">{:lang("_EXPIRED_")}</option>
                                <option value="2">{:lang("_REFUND_")}</option>
                                <option value="0">{:lang("_INVALID_")}</option>
                                <option value="-1">{:lang("_ADMINISTRATOR_DELETE_")}</option>
                            </select>
                        </div>
                    </div>
                    <div class="oneselect">
                        <div class="select_box">
                            <select name="buyer" data-role="select_text" class="form-control">
                                <option value="-1" {eq name="buyer" value="-1"}selected{/eq}>{:lang("_ADMINISTRATOR_GENERATION_")}</option>
                                <option value="1" {eq name="buyer" value="1"}selected{/eq}>{:lang("_USER_PURCHASE_")}</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <!-- 数据表格 -->
    <div class="with-padding">
        <table class="table table-bordered table-striped ">
            <!-- 表头 -->
            <thead>
            <tr>
                <th class="row-selected row-selected">
                    <input class="check-all" type="checkbox">
                </th>
                <th>ID</th>
                <th>{:lang("_INVITATION_CODE_")}</th>
                <th style="width: 250px;">{:lang("_INVITATION_CODE_LINK_")}</th>
                <th>{:lang("_INVITATION_CODE_TYPE_")}</th>
                <th>{:lang("_BUYERS_")}</th>
                <th>{:lang("_CAN_BE_REGISTERED_A_FEW_")}</th>
                <th>{:lang("_ALREADY_REGISTERED_SEVERAL_")}</th>
                <th>{:lang("_PERIOD_OF_VALIDITY_")}</th>
                <th>{:lang("_CREATE_TIME_")}</th>
                <th>{:lang("_OPERATION_")}</th>
            </tr>
            </thead>

            <!-- 列表 -->
            <tbody>
            {volist name="invite_list" id="invite"}
                <tr>
                    <td><input class="ids" type="checkbox" value="{$invite.id}" name="ids[]" data-code="{$invite.code}" data-code-url="{$invite.code_url}"></td>
                    <td>{$invite.id}</td>
                    <td>{$invite.code}</td>
                    <td>{$invite.code_url}</td>
                    <td>{$invite.invite}</td>
                    <td>{$invite.buyer}</td>
                    <td>{$invite.can_num}</td>
                    <td>{$invite.already_num}</td>
                    <td>{$invite.end_time|time_format}</td>
                    <td>{$invite.create_time|time_format}</td>
                    <td>
                        <div style="position: relative;">
                            <a data-role="copy_code" data-code="{$invite.code}">{:lang("_COPY_INVITATION_CODE_")}</a> <a data-role="copy_code_url" data-code-url="{$invite.code_url}" style="margin-left: 10px;">{:lang("_COPY_INVITATION_LINK_")}</a>
                        </div>
                    </td>
                </tr>
            {/volist}

            </tbody>
        </table>

        <div class="page">
        {$page}
        </div>
    </div>
    <!-- 分页 -->
    
{/block}
{block name="script"}
    <script type="text/javascript">
        function toggle_search(){
            $('#search_form').toggle('slide');
        }

        $(document).on('submit', '.form-dont-clear-url-param', function(e){
            e.preventDefault();

            var seperator = "&";
            var form = $(this).serialize();
            var action = $(this).attr('action');
            if(action == ''){
                action = location.href;
            }
            var new_location = action + seperator + form;

            location.href = new_location;

            return false;
        });


    </script>
    <script>
        $(function(){

            $('[data-role="cvs"]').click(function(){
                var data_url=$(this).attr('data-url');
                var form=$('.ids');
                if (form.get(0) == undefined) {
                } else if (form.get(0).nodeName == 'FORM') {
                    query = form.serialize();
                } else if (form.get(0).nodeName == 'INPUT' || form.get(0).nodeName == 'SELECT' || form.get(0).nodeName == 'TEXTAREA') {
                    query = form.serialize();
                } else {
                    query = form.find('input,select,textarea').serialize();
                }
                data_url+='&'+query;
                window.open(data_url);
            });
            $('[data-role="select_text"]').change(function(){
                $('#selectForm').submit();
            });
            //模态弹窗
            $('[data-role="modal_popup"]').click(function(){
                var target_url=$(this).attr('modal-url');
                var data_title=$(this).attr('data-title');
                var target_form=$(this).attr('target-form');
                if(target_form!=undefined){
                    //设置了参数时，把参数加入
                    var form=$('.'+target_form);

                    if (form.get(0) == undefined) {
                        updateAlert({:lang('_NO_OPERATIONAL_DATA_WITH_SINGLE_')},'danger');
                        return false;
                    } else if (form.get(0).nodeName == 'FORM') {
                        query = form.serialize();
                    } else if (form.get(0).nodeName == 'INPUT' || form.get(0).nodeName == 'SELECT' || form.get(0).nodeName == 'TEXTAREA') {
                        query = form.serialize();
                    } else {
                        query = form.find('input,select,textarea').serialize();
                    }
                    if(!query.length){
                        updateAlert({:lang('_NO_OPERATIONAL_DATA_WITH_SINGLE_')},'danger');
                        return false;
                    }
                    target_url=target_url+'&'+query;
                }
                var myModalTrigger = new $.zui.ModalTrigger({
                    'type':'ajax',
                    'url':target_url,
                    'title':data_title
                });
                myModalTrigger.show();
            });
            $('.tox-confirm').click(function(e){
                var text = $(this).attr('data-confirm');
                var result = confirm(text);
                if(result) {
                    return true;
                } else {
                    e.stopImmediatePropagation();
                    e.stopPropagation();
                    e.preventDefault();
                    return false;
                }
            })
        });
    </script>
{/block}